package com.ubxtech.websocket.util;

import com.ubxtech.core.exception.ErrorCode;

/**
 * @author Victor.Xiao
 * @since 2023-09-21 20:43
 **/
public enum WebSocketErrorCode implements ErrorCode {


    /**
     * 120===========
     */
    SOCKET_INSTANCE_NOT_EXISTS_ERROR(500, 1201002, "SOCKET服务不存在"),
    DUPLICATE_LOGIN(500, 1201001, "socket重复连接");

    /*========================================================================================================
     */

    /**
     * HTTP状态码
     */
    private int httpStatus;

    /**
     * 错误码
     */
    private int code;

    /**
     * 错误消息
     */
    private String message;


    public int getHttpStatus() {
        return httpStatus;
    }

    public void setHttpStatus(int httpStatus) {
        this.httpStatus = httpStatus;
    }

    @Override
    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    @Override
    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }


    private WebSocketErrorCode(int httpStatus, int code, String message) {
        this.httpStatus = httpStatus;
        this.code = code;
        this.message = message;
    }

    public static WebSocketErrorCode parseByMessage(String message) {

        for (WebSocketErrorCode errorCodeEnum : WebSocketErrorCode.values()) {
            if (errorCodeEnum.getMessage().equals(message)) {
                return errorCodeEnum;
            }
        }
        return null;
    }
}
